package com.kuzlak.cms.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.callbacks.Callback;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
import org.springdoc.core.customizers.ActuatorOpenApiCustomizer;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
import java.util.Map;

@Configuration
public class SwaggerConfig {

   /* @Bean
    public OpenAPI customOpenAPI() {
     *//*   HeaderParameter headerParameter=new HeaderParameter();

        headerParameter
                .description("Token header parameter")
                .required(true)
                .schema(new io.swagger.v3.oas.models.media.StringSchema());
        Map<String, HeaderParameter> token = Map.of();
        token.put("token",headerParameter);*//*
        Components components = new Components();
        components.headers(Map.of("token",new Header().description("Token header parameter").required(true).schema(new Schema().type("string"))))
                .parameters(Map.of("token",new Parameter().in("query").name("token").description("Token header parameter").required(true).schema(new Schema().type("string"))));
        return new OpenAPI()
                .info(new Info()
                        .title("CMS API")
                        .version("1.0")
                        .description("This is a sample Spring Boot RESTful service using springdoc-openapi and OpenAPI 3.")).components(components);
    }*/
   @Bean
   public OpenApiCustomizer globalHeaderConfig() {
       return (openAPI -> {
           HeaderParameter headerParameter = (HeaderParameter) new HeaderParameter()
                   .name("token")
                   .description("一个全局的请求头参数示例")
                   .required(false);
           Header headersItem = new Header()
                  .description("一个全局的请求头参数示例")
                  .required(false);

        //   openAPI.getComponents().addHeaders("token", headersItem);
           openAPI.getPaths().values().stream()
                   .flatMap(pathItem -> pathItem.readOperations().stream())
                  .forEach(operation ->
                      operation.addParametersItem(headerParameter)
                  );
       });
   }

/*
    @Bean
    public GroupedOpenApi adminApi() {
        return publicApi("admin-api","com.kuzlak.cms.module.sys.controller");
    }
*/


 /*   public GroupedOpenApi publicApi(String title, String packagesToScan) {
        //"com.kuzlak.cms.module.sys.controller"
        return GroupedOpenApi.builder()
                .group(title)
                .packagesToScan(packagesToScan)
                .build();
    }*/
}